package com.hckjsec.oa.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.oa.domain.OaProgramme;
import com.hckjsec.oa.service.IOaProgrammeService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 公司OA日程Controller
 * 
 * @author cyt
 * @date 2022-01-13
 */
@RestController
@RequestMapping("/oa/programme")
public class OaProgrammeController extends BaseController
{
    @Autowired
    private IOaProgrammeService oaProgrammeService;

    /**
     * 查询公司OA日程列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OaProgramme oaProgramme)
    {
        startPage();
        List<OaProgramme> list = oaProgrammeService.selectOaProgrammeList(oaProgramme);
        return getDataTable(list);
    }

    /**
     * 导出公司OA日程列表
     */
    @Log(title = "公司OA日程", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OaProgramme oaProgramme)
    {
        List<OaProgramme> list = oaProgrammeService.selectOaProgrammeList(oaProgramme);
        ExcelUtil<OaProgramme> util = new ExcelUtil<OaProgramme>(OaProgramme.class);
        return util.exportExcel(list, "programme");
    }

    /**
     * 获取公司OA日程详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(oaProgrammeService.selectOaProgrammeById(id));
    }

    /**
     * 新增公司OA日程
     */
    @Log(title = "公司OA日程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaProgramme oaProgramme)
    {
        oaProgramme.setUserName(SecurityUtils.getNickName());
        oaProgramme.setDeptId(SecurityUtils.getDeptId());
        oaProgramme.setUserId(SecurityUtils.getUserId());
        return toAjax(oaProgrammeService.insertOaProgramme(oaProgramme));
    }

    /**
     * 修改公司OA日程
     */
    @Log(title = "公司OA日程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaProgramme oaProgramme)
    {
        return toAjax(oaProgrammeService.updateOaProgramme(oaProgramme));
    }

    /**
     * 删除公司OA日程
     */
    @Log(title = "公司OA日程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaProgrammeService.deleteOaProgrammeByIds(ids));
    }
}
